//-------------------------------------------------------------------
//	Copyright (c) 2010-2014  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_STL_Ext.h".
//-------------------------------------------------------------------

#ifndef _UXS_WINDOWS_TIMER_H
#define _UXS_WINDOWS_TIMER_H

#pragma once

#include "OSWindows.h"
#include "../Base/Date.h"

#ifdef PLATFORM_WINDOWS

namespace UX_STL
{
namespace _platform_
{
	
#ifdef PLATFORM_WINDOWS_SHELL

	//
	// Perfomance Timer
	//

	struct PerfTimer
	{
	private:
		LARGE_INTEGER	_liFreq;

	public:
		PerfTimer ()
		{
			QueryPerformanceFrequency( &_liFreq );
		}

		// seconds
		double GetTime () const
		{
			LARGE_INTEGER	perf_counter;
			QueryPerformanceCounter( &perf_counter );
			return ( (double)perf_counter.QuadPart / (double)_liFreq.QuadPart );
		}

		// milliseconds
		uint64 GetTimeMilliSec () const
		{
			LARGE_INTEGER	perf_counter;
			QueryPerformanceCounter( &perf_counter );
			return uint64( (perf_counter.QuadPart * 1000) / _liFreq.QuadPart );
		}

		// microseconds
		uint64 GetTimeMicroSec () const
		{
			LARGE_INTEGER	perf_counter;
			QueryPerformanceCounter( &perf_counter );
			return uint64( (perf_counter.QuadPart * 1000000) / _liFreq.QuadPart );
		}
	};

#endif	// PLATFORM_WINDOWS_SHELL


	
	// Now
	inline Date & Date::Now ()
	{
		SYSTEMTIME	 time = {0};
		GetLocalTime( &time );

		year			= time.wYear;
		month			= time.wMonth;									// 1..12
		dayOfWeek		= time.wDayOfWeek == 0 ? 6 : time.wDayOfWeek-1;	// 0..6, Sun == 0
		day				= time.wDay;									// 1..31
		_CalcDayOfYear();
		
		hour			= time.wHour;									// 0..23
		minute			= time.wMinute;									// 0..59
		second			= time.wSecond;									// 0..59
		milliseconds	= time.wMilliseconds;							// 0..999

		return *this;
	}

	
//-------------------------------------------------------------------

}	// _platform_
}	// UX_STL

#endif	// PLATFORM_WINDOWS
#endif	// _UXS_WINDOWS_TIMER_H